using System;
using System.Globalization;

namespace Prometheus.Binding.ReadOnly.BaseConverters
{
    public class proStringToFirstNSymbolsConverter : proChainConverter
    {
        private int _resultStringLength = 50;

        public int ResultStringLength
        {
            get { return _resultStringLength; }
            set { _resultStringLength = value; }
        }

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;

            string str = value.ToString();
            if (ResultStringLength < str.Length)
            {
                return str.Substring(0, ResultStringLength);
            }
            return value;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}